/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.brain.inve.manager;

import com.brain.conf.dto.ProductoDetaDto;
import com.brain.core.manager.*;
import com.brain.core.exception.DAOException;
import com.brain.core.hibernate.dao.DAOGenerico;
import com.brain.inve.dto.HistorialStockDto;
import com.brain.inve.dto.StockDto;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

/**
 *
 * @author Indra
 */
@Service
public class HistorialStockManager extends ComunManager<HistorialStockDto> implements Serializable {

    private static Logger logger = Logger.getLogger(HistorialStockManager.class);
    private Long idEntidad = 189L;
    @Resource
    private DAOGenerico<HistorialStockDto> springHibernateDao;
    @Resource
    private RecursosManager recursosManager;
    private final String urlLista = "/pages/inve/stock/consultaStocks.xhtml";

    public List<HistorialStockDto> obtenerHistorialPorProductoDetaYAlmUbi(StockDto dto) throws DAOException {
        String hqsql = "select e from HistorialStockDto as e where e.id=e.id ";
        List<Object> listaParametros = new ArrayList<Object>();
        hqsql += " and e.productoDetaDto.id = ?";
        listaParametros.add(dto.getStockDtoPK().getProductoDetaDto().getId());
        hqsql += " and e.almacenUbicacionDto.id = ?";
        listaParametros.add(dto.getStockDtoPK().getAlmacenUbicacionDto().getId());
        hqsql += " order by e.fecha desc";
        return springHibernateDao.ejecutarQuery(hqsql, listaParametros);
    }        
    
    public List<HistorialStockDto> obtenerHistorialPorProductoDeta(ProductoDetaDto dto) throws DAOException {
        String hqsql = "select e from HistorialStockDto as e where e.id=e.id ";
        List<Object> listaParametros = new ArrayList<Object>();
        hqsql += " and e.productoDetaDto.id = ?";
        listaParametros.add(dto.getId());
        hqsql += " order by e.fecha desc";
        return springHibernateDao.ejecutarQuery(hqsql, listaParametros);
    }  

    public void nuevoMuchos(List<HistorialStockDto> lista) throws DAOException {
        springHibernateDao.guardarColeccion(lista);
    }

    public void eliminarMuchos(List<HistorialStockDto> lista) throws DAOException {
        springHibernateDao.borrarColeccion(lista);
    }

    public static Logger getLogger() {
        return logger;
    }

    public static void setLogger(Logger logger) {
        HistorialStockManager.logger = logger;
    }

    public Long getIdEntidad() {
        return idEntidad;
    }

    public void setIdEntidad(Long idEntidad) {
        this.idEntidad = idEntidad;
    }

    public DAOGenerico<HistorialStockDto> getSpringHibernateDao() {
        return springHibernateDao;
    }

    public void setSpringHibernateDao(DAOGenerico<HistorialStockDto> springHibernateDao) {
        this.springHibernateDao = springHibernateDao;
    }

    public RecursosManager getRecursosManager() {
        return recursosManager;
    }

    public void setRecursosManager(RecursosManager recursosManager) {
        this.recursosManager = recursosManager;
    }

    public String getUrlLista() {
        return urlLista;
    }
}
